package com.palmwindActivity.app.main;

import java.io.IOException;
import java.net.UnknownHostException;

import javax.net.SocketFactory;

import android.content.Context;

import com.palmwindActivity.app.AbstractCommManager;

public class DemoCommManager extends AbstractCommManager {

	public static String SERVER_URL = "192.168.1.100";
	public static int PORT = 10001;
	protected Context context;
	public DemoCommManager(Context context)
	{
		super();
		this.context = context;
	}

	
    protected void initSocket(String url, int port) throws UnknownHostException, IOException
    {
        connectedSocket = SocketFactory.getDefault().createSocket(url, port);
        if (connectedSocket != null)
        {
            isConnected = true;
        }
    }

	public void openConnection() throws UnknownHostException, IOException {
		String serverURL = context.getSharedPreferences("Settings", 0).getString("ip", "");
		if(serverURL.length() > 0)
		{
			initSocket(serverURL, PORT);
		}
		else
		{
			initSocket(SERVER_URL, PORT);
		}
	}


	public void close() throws IOException {
		if(connectedSocket != null)
		{
			connectedSocket.close();
			isConnected = false;
		}
	}

}
